<template>
	<el-dialog :title="title" :visible.sync="dialogVisible" width="650px" @close="handleClose"
		:close-on-click-modal="false"
		:append-to-body="true">
		<div slot="title" class="dialog-header-title">
			<i class="el-icon-edit-outline"></i>
			<span>{{title}}</span>
		</div>

		<div class="smp-search" v-if="dialogVisible">
			<el-form :inline="false" label-width="100px" size="mini" ref="form" :model="form" :rules="rules">

				<el-row>
						<el-col :span="24">
							<el-form-item label="路由类型:" prop="sourceType" >
								<el-select v-model="form.sourceType" style="width: 100%" placeholder="字符编码" disabled>
									<el-option v-for="item in dict('SMP0023')" :key="item.itemCode" :label="item.itemName" :value="item.itemCode"></el-option>
								</el-select>
								
							</el-form-item>
						</el-col>
						
						<el-col :span="24">
							<el-form-item label="内外联标识:" prop="sourceType" >
								<el-select v-model="form.esbFlg" style="width: 100%" placeholder="字符编码" disabled>
									<el-option v-for="item in dict('SMP0031')" :key="item.itemCode" :label="item.itemName" :value="item.itemCode"></el-option>
								</el-select>
								
							</el-form-item>
						</el-col>
						
					<!-- 	<el-col :span="24" v-if="form.sourceType=='01' || form.sourceType=='03'">
							<el-form-item label="资源目录:" prop="sourceFolder"  >
								
								<el-input v-model="form.sourceFolder" placeholder="资源目录" disabled></el-input>
								
							</el-form-item>
						</el-col> -->

						<el-col :span="24">
							<el-form-item label="路由名称:" prop="sourceName">
								<el-input v-model="form.sourceName" placeholder="资源名称:eg:核心业务路由"></el-input>
							</el-form-item>
						</el-col>
						
						<el-col :span="24">
							<el-form-item label="路由全路径:" prop="sourcePath">
								<el-input v-model="form.sourcePath" placeholder="路由路径:eg:AHRCUApp/BusinessService/CBS/TPSRV_CBS_BusinessService"></el-input>
							</el-form-item>
						</el-col>
						
						<el-col :span="24">
							<el-form-item label="路由描述:" prop="sourceDesc">
								<el-input type="textarea" v-model="form.sourceDesc" placeholder="路由描述"></el-input>
							</el-form-item>
						</el-col>
				</el-row>
			</el-form>
		</div>
		<span slot="footer" class="dialog-footer">
			<el-button size="mini" type="primary" @click="onSubmit">
				<i class="el-icon-check"></i>
				确定</el-button>
			<el-button size="mini" @click="closeDialog">
				<i class="el-icon-close"></i>
				取消</el-button>
		</span>
	</el-dialog>
</template>

<script>
	"use strict";
	import { addEsbSourceInfo } from '@/api/source.js';

	export default {
		
		data() {
			return {
				dialogVisible: false,
				title:'',
				rules: {
					sourceType: [{
						required: true,
						message: "资源类型不能为空",
						trigger: ['blur', 'change']
					}],
					sourceName: [{
						required: true,
						message: "资源名称不能为空",
						trigger: ['blur', 'change']
					}],
					sourcePath: [{
						required: true,
						message: "资源路径不能为空",
						trigger: ['blur', 'change']
					}]
				},
				form: {
					sourcePath: '',
					sourceType: '',
					sourceName: '',
					sourceDesc: '',
					sourceFolder:'',
					esbFlg:''
				},

			};
		},


		methods: {
			
			onSubmit() {
				this.addEsbSourceInfo();
			},
						
			addEsbSourceInfo() {
				this.$refs["form"].validate(valid => {
					if (valid) {
						addEsbSourceInfo(this.form).then(response => {
							if(response.data.code == "0000"){
								this.$message.success(response.data.message);
								// this.$message({
						//duration:5000,
								// 	type: 'success',
								// 	message: '核心路由新增成功！'
								// });
								this.dialogVisible = false;
								if(this.form.esbFlg=='01'){
									if(this.form.sourceType=='01'){
										this.$emit("changeProxyPath",this.form.sourcePath);
									}else if(this.form.sourceType=='02'){
										this.$emit("changeLocalPath",this.form.sourcePath);
									}else{
										this.$emit("changebusPath",this.form.sourcePath);
									}
								}else{
									if(this.form.sourceType=='01'){
										this.$emit("changeoesbProxyPath",this.form.sourcePath);
									}else if(this.form.sourceType=='02'){
										this.$emit("changeoesbLocalPath",this.form.sourcePath);
									}else{
										this.$emit("changeoesbbusPath",this.form.sourcePath);
									}
								}
								this.reset();
							}else{
								this.$message.error(response.data.message);
							}
						}).catch(error => {
							this.$message({
						duration:5000,								type: 'error',
								message: '核心路由新增失败！'
							});
							this.reset();
							this.dialogVisible = false;
						});
					}
				})

			},
			
			
			
			showDialog(sourceType,sourceFolder,esbFlg) {
				this.form.sourceType = sourceType;
				this.form.sourceFolder= sourceFolder;
				this.form.sourcePath= sourceFolder;
				this.form.esbFlg= esbFlg;
				if(sourceType=='02'){
					this.title="本地路由配置"
				}else if(sourceType=='03'){
					this.title="服务路由配置"
				}else{
					this.title="代理路径"
				}
				
				
				
				this.dialogVisible = true;

			},

			closeDialog() {
				this.reset();
				this.dialogVisible = false;
			},

			handleClose() {
				this.reset();
				this.dialogVisible = false;
			}


		},

	}
</script>

<style>
</style>
